<!--
 * @Author: 小花
 * @Date: 2022-03-06 13:10:33
 * @LastEditors: 小花
 * @LastEditTime: 2022-04-18 16:25:01
 * @Description: 
-->
<template>
  <div class='el-menu_container'>
    <el-menu :default-active="defaultActive" mode="horizontal" :ellipsis="false" class="el_menu"
      router>
      <div class="user_info_box">
        <el-avatar :src="userInfo.headimgurl"></el-avatar>
        <div style="display: inline-block;">
          <div class="userInfo">
            <span class="nickname"> {{userInfo.nickname}} </span>
            <span class="loginType"> {{swapLoginType}} </span>
          </div>
        </div>
        <el-menu-item v-for="(item, index) in el_menu_item" :key="index" :index="item.index">
          <template #title>
            {{item.name}}
          </template>
        </el-menu-item>
      </div>
      <div class="logOut" @click="logOut">
        安全退出
      </div>
    </el-menu>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { clearLoginInfo, getUserInfo } from '@/js/public'

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  props: ['el_menu_item'],
  data () {
    //这里存放数据
    return {
      userInfo: { ...getUserInfo() },
    }
  },
  //监听属性 类似于data概念
  computed: {
    getCurrentRouter () {
      return this.$route.fullPath
    },
    swapLoginType () {
      switch (this.userInfo.loginType) {
        case 'user':
          return '普通用户'
        case 'worker':
          return '维修员'
        default:
          return '未知'
      }
    },
    defaultActive () {
      return this.$route.path;
    }
  },
  //方法集合
  methods: {
    logOut () {
      clearLoginInfo();
      this.$router.replace({ name: "wxScanLogin", replace: true })
    },
  }
}
</script>

<style lang='scss' scoped>
.el-menu_container {
  .el_menu {
    // 导航栏背景色
    background: $element_primary;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    .user_info_box {
      display: flex;
      padding: 10px;
      align-items: center;
    }
    .logOut {
      font-size: 14px;
      cursor: pointer;
      color: $element_text_primary;
    }
    .userInfo {
      display: flex;
      flex-direction: column;
      line-height: normal;
      text-align: center;
      .loginType {
        // 用户类型（小椭圆）背景色
        background: $element_text_perch;
        border-radius: 2rem;
        font-size: 12px;
        padding: 0 3px;
      }
    }
    .el-menu-item {
      // 导航栏字体颜色
      color: $element_text_primary;
      background: none;
      &:hover {
        background: none;
      }
    }
    .is-active {
      color: $element_text_primary !important;
      font-weight: bold;
      border-bottom: 4px solid $element_border_1;
      background: none !important;
    }
  }
}
</style>